<template>
  <div id="imagesList" v-loading="dataLoading">
    <div
      class="item"
      v-for="(item, index) in backgroundImgs"
      :key="index"
      @click="itemClick(item)"
    >
      <img
        :style="{
          backgroundImage: 'url(/' + item.resourcesSrc + ')',
        }"
        :src="require('@/assets/images/' + 'logo3.png')"
      />
      <div>{{ item.resourcesName }}</div>
    </div>
  </div>
</template>

<script>
export default {
  name: "imagesList",
  props: ["activate"],
  data() {
    return {
      loaded: false, // 是否已激活
      dataLoading: false,
      backgroundImgs: [],
    };
  },
  watch: {
    activate: {
      handler: "activateChange",
      deep: true,
    },
  },
  created() {
    this.activateChange();
  },
  mounted() {},
  methods: {
    /**
     * 监听现在激活的tab
     **/
    activateChange() {
      if (this.activate && !this.loaded) {
        // 如果未加载过，现在开始加载
        this.loaded = true;
        this.getData(); // 获取资源列表
      }
    },
    /**
     * 获取资源列表
     * @param
     */
    async getData() {
      // TODO 走接口取数据
      this.backgroundImgs = [
        { resourcesName: "无边框", resourcesType: 1, resourcesSrc: "" },
        {
          resourcesName: "边框1",
          resourcesType: 1,
          resourcesSrc:
            "microPageModulesResources/images/multiPage/images/bg1.png",
        },
        {
          resourcesName: "边框2",
          resourcesType: 1,
          resourcesSrc:
            "microPageModulesResources/images/multiPage/images/bg2.png",
        },
        {
          resourcesName: "边框3",
          resourcesType: 1,
          resourcesSrc:
            "microPageModulesResources/images/multiPage/images/bg3.png",
        },
        {
          resourcesName: "边框4",
          resourcesType: 1,
          resourcesSrc:
            "microPageModulesResources/images/multiPage/images/bg4.png",
        },
        {
          resourcesName: "边框5",
          resourcesType: 1,
          resourcesSrc:
            "microPageModulesResources/images/multiPage/images/bg5.png",
        },
        {
          resourcesName: "边框6",
          resourcesType: 1,
          resourcesSrc:
            "microPageModulesResources/images/multiPage/images/bg6.png",
        },
        {
          resourcesName: "边框7",
          resourcesType: 1,
          resourcesSrc:
            "microPageModulesResources/images/multiPage/images/bg7.png",
        },
        {
          resourcesName: "边框8",
          resourcesType: 1,
          resourcesSrc:
            "microPageModulesResources/images/multiPage/images/bg8.png",
        },
        {
          resourcesName: "边框9",
          resourcesType: 1,
          resourcesSrc:
            "microPageModulesResources/images/multiPage/images/bg9.png",
        },
        {
          resourcesName: "边框10",
          resourcesType: 1,
          resourcesSrc:
            "microPageModulesResources/images/multiPage/images/bg10.png",
        },
        {
          resourcesName: "边框11",
          resourcesType: 1,
          resourcesSrc:
            "microPageModulesResources/images/multiPage/images/bg11.png",
        },
      ];
    },
    /**
     * 项目点击返回该项信息
     * @param item
     */
    itemClick(item) {
      this.$emit("selectedImg", item); // 向父级传递参数
    },
  },
};
</script>

<style lang='scss' scoped>
#imagesList {
  width: 100%;
  height: 100%;
  position: relative;
  overflow-y: auto;
  .item {
    width: 100%;
    height: 120px;
    text-align: center;
    margin-bottom: 20px;
    cursor: pointer;
    img {
      width: 100px;
      height: 100px;
      display: block;
      margin: 0 auto;
      border-radius: 5px;
      -webkit-box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
      box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
      background-repeat: no-repeat;
      background-size: 100% 100%;
    }
    div {
      font-size: 14px;
      line-height: 30px;
    }
  }
  .item:hover {
    img {
      -webkit-box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.3);
      box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.3);
    }
    div {
      font-size: 15px;
    }
  }
}
#imagesList::-webkit-scrollbar-track-piece {
  // 滚动条凹槽的颜色，还可以设置边框属性
  background-color: #f8f8f8;
}
#imagesList::-webkit-scrollbar {
  // 滚动条的宽度
  width: 6px;
  height: 6px;
}
#imagesList::-webkit-scrollbar-thumb {
  // 滚动条的设置
  background-color: #dddddd;
  background-clip: padding-box;
  min-height: 28px;
  border-top-left-radius: 5px;
  border-bottom-left-radius: 5px;
}
#imagesList::-webkit-scrollbar-thumb:hover {
  background-color: #bbb;
}
</style>
